﻿using AbpDemo.Filters;
using CSRedis;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AutoMapper;
using Volo.Abp.Modularity;

namespace AbpDemo;

[DependsOn(
    typeof(AbpDemoDomainModule),
    typeof(AbpDemoApplicationContractsModule)
    )]
public class AbpDemoApplicationModule : AbpModule
{
    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        Configure<AbpAutoMapperOptions>(options =>
        {
            options.AddMaps<AbpDemoApplicationModule>();
        });

        context.Services.AddSwaggerGen(options => { 
            options.SchemaFilter<SchemaFilter>();
        });

        CSRedisClient redisClient = new CSRedisClient(context.Services.GetConfiguration().GetConnectionString("RedisStr"));

        context.Services.AddSingleton(redisClient);

        //注册
        context.Services.AddHostedService<SendEmailService>();

        context.Services.AddHttpContextAccessor();

        context.Services.AddAuthorization(options => {
            options.AddPolicy("", builder => {
                builder.RequireClaim("role", "");
            });
        });
    }
}
